package pojo;

import algorithm.easy.FairCandySwap888;

import java.util.*;
import java.util.stream.Collector;
import java.util.stream.Collectors;

/**
 * @BelongsProject: LeetCode
 * @BelongsPackage: pojo
 * @Author: 江岸
 * @CreateTime: 2021-06-08 09:10
 * @Description:
 */
public class Person {
    public static void main(String[] args) {
        System.out.println(strToNum("23s41"));
//        int[] ints = {3, 5, 7, 9, 8, 6, 4, 2, 12};
//        List<Integer> collect = Arrays.stream(ints).boxed().collect(Collectors.toList());
//        System.out.println(topMinN(collect,4));
    }

    public static int strToNum(String str){
        if (!str.matches("^-?[1-9]\\d*$")) throw new NumberFormatException("不规范的格式");//匹配整数
        char[] chars = str.toCharArray();
        int res = 0;
        for (int i=0;i<chars.length;i++){
            res = res*10 + chars[i]-'0';
        }
        return res;
    }

    //求最小的n个数
    public static List<Integer> topMinN(List<Integer> list,int n){
        PriorityQueue<Integer> pq = new PriorityQueue<>(Comparator.comparing((o)->-o));
        for (int i=0;i<list.size();i++){
            if (pq.size()<n){
                pq.add(list.get(i));
            }else{
                Integer peek = pq.peek();
                if (list.get(i)<peek){
                    pq.add(list.get(i));
                    pq.poll();
                }
            }
        }
        ArrayList<Integer> arrayList = new ArrayList(pq);
        return arrayList;
    }
}
